package 设计模式.结构型.Flyweight享元.square;

import java.util.HashMap;

/**
 * 享元工厂
 *
 * @author: 张从龙
 * time: 2022/8/15 15:35
 */
public class BoxFactory {

    private final HashMap<String, AbstractBox> map;
    private static final BoxFactory factory = new BoxFactory();

    //在构造方法中进行初始化操作
    private BoxFactory(){
        map = new HashMap<>();
        map.put("I", new IBox());
        map.put("L", new LBox());
        map.put("O", new OBox());
    }

    //提供方法获取工厂 -- 饿汉式 单例
    public static BoxFactory getInstance(){
        return factory;
    }

    //根据名称获取图形对象
    public AbstractBox getShape(String name){
        return map.get(name);
    }
}